﻿Imports System.Data.SqlClient
Imports QuanLyBanChau.Chau


Public Class Chau_dao

    Public Shared Sub insertChaudao(ByVal chau As Chau)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("insert_Chau", conn)
        cmd.CommandType = CommandType.StoredProcedure

        para = New SqlParameter("@Machau", SqlDbType.VarChar, 10)
        para.Value = chau.Machau
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Tenchau", SqlDbType.NVarChar, 100)
        para.Value = chau.Tenchau
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Maloai", SqlDbType.VarChar, 10)
        para.Value = chau.Maloai
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Trigia", SqlDbType.Int)
        para.Value = chau.Trigia
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Kichthuoc", SqlDbType.Int)
        para.Value = chau.Kichthuoc
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Soluong", SqlDbType.Int)
        para.Value = chau.Soluong
        cmd.Parameters.Add(para)

        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub


    Public Shared Sub DeleteChaudao(ByVal Machau)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Delete_Chau", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para = New SqlParameter("@Machau", SqlDbType.VarChar, 10)
        para.Value = Machau
        cmd.Parameters.Add(para)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub


    Public Shared Function Get_Chaudao()
        Dim conn As SqlConnection
        conn = dataprovider.Connection()
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        da.SelectCommand = New SqlCommand
        da.SelectCommand.Connection = conn
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        da.SelectCommand.CommandText = "Get_Chau"
        da.Fill(dt)
        Return dt
    End Function


    Public Shared Sub updateChaudao(ByVal chau As Chau)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Update_Chau", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para = New SqlParameter("@Machau", SqlDbType.VarChar, 10)
        para.Value = chau.Machau
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Tenchau", SqlDbType.NVarChar, 100)
        para.Value = chau.Tenchau
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Maloai", SqlDbType.VarChar, 10)
        para.Value = chau.Maloai
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Trigia", SqlDbType.Int)
        para.Value = chau.Trigia
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Kichthuoc", SqlDbType.Int)
        para.Value = chau.Kichthuoc
        cmd.Parameters.Add(para)

        para = New SqlParameter("@Soluong", SqlDbType.Int)
        para.Value = chau.Soluong
        cmd.Parameters.Add(para)

        cmd.ExecuteNonQuery()
        'cmd.Dispose()
        conn.Close()
    End Sub
End Class
